home *** CD-ROM | disk | FTP | other *** search
- #include "includes.h"
- #include "defines.h"
- #include "funcs.h"
-
- void jookyclient(host,cmd)
- char *host;
- char *cmd;
- {
- char *buf;
- char *greeting;
- int sockfd ;
- struct hostent *he ;
- struct sockaddr_in their_addr ;
-
- buf=calloc(1,2048);
- greeting=calloc(1,2048);
-
- if ((he=gethostbyname(host)) == NULL)
- {
- perror("gethostbyname");
- exit(1);
- }
-
- if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
- {
- perror("socket");
- exit(1);
- }
-
- their_addr.sin_family = AF_INET;
- their_addr.sin_port = htons(port);
- their_addr.sin_addr = *((struct in_addr *)he->h_addr);
- bzero(&(their_addr.sin_zero),8);
-
- if (connect(sockfd,(struct sockaddr *)&their_addr,\
- sizeof(struct sockaddr)) == -1)
- {
- perror("connect");
- exit(1);
- }
-
- read(sockfd,greeting,80);
- if ((strncmp(greeting,"welcome!",8)==0) && (usepasswd==1))
- {
- printf("no password required.\n");
- shutdown(sockfd,2);
- free(buf);
- exit(0);
- }
-
- if ((strncmp(greeting,"password:",9)==0) && (usepasswd==0))
- {
- printf("password required!\n");
- shutdown(sockfd,2);
- free(buf);
- exit(0);
- }
-
- if ((strncmp(greeting,"password:",9)==0) && (usepasswd==1))
- {
- usleep(100000);
- write(sockfd,password,strlen(password));
- }
-
- usleep(100000);
- write(sockfd,cmd,strlen(cmd));
- usleep(100000);
-
- if (strncmp(cmd,"quer",4)==0)
- {
- read(sockfd,buf,2048);
- printf ("%s\n",buf);
- }
-
- shutdown(sockfd,2);
- free(buf);
- exit(0);
- }
-